﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WMS_Business;
using WMS_Model;

namespace WMSFlatApp
{
    public partial class FrmIndex : Form
    {
        private string workName { get; set; }  //当前工位名
        RequestManage request;

        private AutoSizeFormClass asc = new AutoSizeFormClass();
        public FrmIndex()
        {
            InitializeComponent();
            asc.controllInitializeSize(this);  //控件居中
            request = new RequestManage();

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //窗体变的很卡还一直闪烁处理方法
            SetStyle(ControlStyles.UserPaint, true);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true);//禁止擦除背景.
            SetStyle(ControlStyles.OptimizedDoubleBuffer, true);//双缓冲
            this.UpdateStyles();
            //绑定工位下拉列表
            cmbTitle.DataSource = request.Stationlist();
        }
        /// <summary>
        /// 控件随窗体等比例放大
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Form1_Resize(object sender, EventArgs e)
        {
            asc.controlAutoSize(this);
        }
        /// <summary>
        /// 呼料按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnHu_Click(object sender, EventArgs e)
        {
            FrmHu hu = new FrmHu(workName);
            hu.ShowDialog();
        }

        private void btnFang_Click(object sender, EventArgs e)
        {
            FrmFang fang = new FrmFang(workName);
            fang.ShowDialog();
        }

        /// <summary>
        /// Combobox控件选中值修改时触发
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cmbTitle_SelectionChangeCommitted(object sender, EventArgs e)
        {
            txtHU.Clear();    //为防止选中工位重复查询，先清除在查询
            txtFang.Clear();
            workName = cmbTitle.SelectedItem.ToString(); //通过下拉框选中工位名称
            List<TasksTable> listHu = request.Tasks(workName, "呼料");
            int idHU, idFang;
            idHU = idFang = 0;
            foreach (var item in listHu)
            {
                idHU++;
                txtHU.AppendText(idHU + ":" + "工位:【" + workName + "】" + "物料【" + item.MaterialName + "】" + "起点【" + item.RiseSpot + "】" + "终点【" + item.EndSpot + "】" + "数量【" + item.MaterialNumber + "】" + "呼料状态【" + item.TaskStatus + "】" + "\r\n");
            }

            List<TasksTable> listFang = request.Tasks(workName, "放料");
            foreach (var item in listFang)
            {
                idFang++;
                txtFang.AppendText(idFang + ":" + "工位:【" + workName + "】" + "物料【" + item.MaterialName + "】" + "起点【" + item.RiseSpot + "】" + "终点【" + item.EndSpot + "】" + "数量【" + item.MaterialNumber + "】" + "放料状态【" + item.TaskStatus + "】" + "\r\n");
            }
        }
    }
}
